<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>Pagination &mdash; Django 1.7.8.dev20150401230226 documentation</title>
    
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '1.7.8.dev20150401230226',
        COLLAPSE_INDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/underscore.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="Django 1.7.8.dev20150401230226 documentation" href="../index.html" />
    <link rel="up" title="Using Django" href="index.html" />
    <link rel="next" title="Porting to Python 3" href="python3.html" />
    <link rel="prev" title="Logging" href="logging.html" />



 
<script type="text/javascript" src="../templatebuiltins.js"></script>
<script type="text/javascript">
(function($) {
    if (!django_template_builtins) {
       // templatebuiltins.js missing, do nothing.
       return;
    }
    $(document).ready(function() {
        // Hyperlink Django template tags and filters
        var base = "../ref/templates/builtins.html";
        if (base == "#") {
            // Special case for builtins.html itself
            base = "";
        }
        // Tags are keywords, class '.k'
        $("div.highlight\\-html\\+django span.k").each(function(i, elem) {
             var tagname = $(elem).text();
             if ($.inArray(tagname, django_template_builtins.ttags) != -1) {
                 var fragment = tagname.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + tagname + "</a>");
             }
        });
        // Filters are functions, class '.nf'
        $("div.highlight\\-html\\+django span.nf").each(function(i, elem) {
             var filtername = $(elem).text();
             if ($.inArray(filtername, django_template_builtins.tfilters) != -1) {
                 var fragment = filtername.replace(/_/, '-');
                 $(elem).html("<a href='" + base + "#" + fragment + "'>" + filtername + "</a>");
             }
        });
    });
})(jQuery);
</script>


  </head>
  <body>

    <div class="document">
  <div id="custom-doc" class="yui-t6">
    <div id="hd">
      <h1><a href="../index.html">Django 1.7.8.dev20150401230226 documentation</a></h1>
      <div id="global-nav">
        <a title="Home page" href="../index.html">Home</a>  |
        <a title="Table of contents" href="../contents.html">Table of contents</a>  |
        <a title="Global index" href="../genindex.html">Index</a>  |
        <a title="Module index" href="../py-modindex.html">Modules</a>
      </div>
      <div class="nav">
    &laquo; <a href="logging.html" title="Logging">previous</a>
     |
    <a href="index.html" title="Using Django" accesskey="U">up</a>
   |
    <a href="python3.html" title="Porting to Python 3">next</a> &raquo;</div>
    </div>

    <div id="bd">
      <div id="yui-main">
        <div class="yui-b">
          <div class="yui-g" id="topics-pagination">
            
  <div class="section" id="s-module-django.core.paginator">
<span id="s-pagination"></span><span id="module-django.core.paginator"></span><span id="pagination"></span><h1>Pagination<a class="headerlink" href="#module-django.core.paginator" title="Permalink to this headline">¶</a></h1>
<p>Django provides a few classes that help you manage paginated data &#8211; that is,
data that&#8217;s split across several pages, with &#8220;Previous/Next&#8221; links. These
classes live in <tt class="file docutils literal"><span class="pre">django/core/paginator.py</span></tt>.</p>
<div class="section" id="s-example">
<span id="example"></span><h2>Example<a class="headerlink" href="#example" title="Permalink to this headline">¶</a></h2>
<p>Give <a class="reference internal" href="#django.core.paginator.Paginator" title="django.core.paginator.Paginator"><tt class="xref py py-class docutils literal"><span class="pre">Paginator</span></tt></a> a list of objects, plus the number of items you&#8217;d like to
have on each page, and it gives you methods for accessing the items for each
page:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="gp">&gt;&gt;&gt; </span><span class="kn">from</span> <span class="nn">django.core.paginator</span> <span class="kn">import</span> <span class="n">Paginator</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">objects</span> <span class="o">=</span> <span class="p">[</span><span class="s">&#39;john&#39;</span><span class="p">,</span> <span class="s">&#39;paul&#39;</span><span class="p">,</span> <span class="s">&#39;george&#39;</span><span class="p">,</span> <span class="s">&#39;ringo&#39;</span><span class="p">]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span> <span class="o">=</span> <span class="n">Paginator</span><span class="p">(</span><span class="n">objects</span><span class="p">,</span> <span class="mi">2</span><span class="p">)</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">count</span>
<span class="go">4</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">num_pages</span>
<span class="go">2</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">page_range</span>
<span class="go">[1, 2]</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">page1</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page1</span>
<span class="go">&lt;Page 1 of 2&gt;</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page1</span><span class="o">.</span><span class="n">object_list</span>
<span class="go">[&#39;john&#39;, &#39;paul&#39;]</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span> <span class="o">=</span> <span class="n">p</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mi">2</span><span class="p">)</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">object_list</span>
<span class="go">[&#39;george&#39;, &#39;ringo&#39;]</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">has_next</span><span class="p">()</span>
<span class="go">False</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">has_previous</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">has_other_pages</span><span class="p">()</span>
<span class="go">True</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">next_page_number</span><span class="p">()</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">EmptyPage</span>: <span class="n">That page contains no results</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">previous_page_number</span><span class="p">()</span>
<span class="go">1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">start_index</span><span class="p">()</span> <span class="c"># The 1-based index of the first item on this page</span>
<span class="go">3</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">page2</span><span class="o">.</span><span class="n">end_index</span><span class="p">()</span> <span class="c"># The 1-based index of the last item on this page</span>
<span class="go">4</span>

<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mi">0</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">EmptyPage</span>: <span class="n">That page number is less than 1</span>
<span class="gp">&gt;&gt;&gt; </span><span class="n">p</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mi">3</span><span class="p">)</span>
<span class="gt">Traceback (most recent call last):</span>
<span class="c">...</span>
<span class="gr">EmptyPage</span>: <span class="n">That page contains no results</span>
</pre></div>
</div>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">Note that you can give <tt class="docutils literal"><span class="pre">Paginator</span></tt> a list/tuple, a Django <tt class="docutils literal"><span class="pre">QuerySet</span></tt>,
or any other object with a <tt class="docutils literal"><span class="pre">count()</span></tt> or <tt class="docutils literal"><span class="pre">__len__()</span></tt> method. When
determining the number of objects contained in the passed object,
<tt class="docutils literal"><span class="pre">Paginator</span></tt> will first try calling <tt class="docutils literal"><span class="pre">count()</span></tt>, then fallback to using
<tt class="docutils literal"><span class="pre">len()</span></tt> if the passed object has no <tt class="docutils literal"><span class="pre">count()</span></tt> method. This allows
objects such as Django&#8217;s <tt class="docutils literal"><span class="pre">QuerySet</span></tt> to use a more efficient <tt class="docutils literal"><span class="pre">count()</span></tt>
method when available.</p>
</div>
</div>
<div class="section" id="s-using-paginator-in-a-view">
<span id="using-paginator-in-a-view"></span><h2>Using <tt class="docutils literal"><span class="pre">Paginator</span></tt> in a view<a class="headerlink" href="#using-paginator-in-a-view" title="Permalink to this headline">¶</a></h2>
<p>Here&#8217;s a slightly more complex example using <a class="reference internal" href="#django.core.paginator.Paginator" title="django.core.paginator.Paginator"><tt class="xref py py-class docutils literal"><span class="pre">Paginator</span></tt></a> in a view to
paginate a queryset. We give both the view and the accompanying template to
show how you can display the results. This example assumes you have a
<tt class="docutils literal"><span class="pre">Contacts</span></tt> model that has already been imported.</p>
<p>The view function looks like this:</p>
<div class="highlight-python"><div class="highlight"><pre><span class="kn">from</span> <span class="nn">django.core.paginator</span> <span class="kn">import</span> <span class="n">Paginator</span><span class="p">,</span> <span class="n">EmptyPage</span><span class="p">,</span> <span class="n">PageNotAnInteger</span>

<span class="k">def</span> <span class="nf">listing</span><span class="p">(</span><span class="n">request</span><span class="p">):</span>
    <span class="n">contact_list</span> <span class="o">=</span> <span class="n">Contacts</span><span class="o">.</span><span class="n">objects</span><span class="o">.</span><span class="n">all</span><span class="p">()</span>
    <span class="n">paginator</span> <span class="o">=</span> <span class="n">Paginator</span><span class="p">(</span><span class="n">contact_list</span><span class="p">,</span> <span class="mi">25</span><span class="p">)</span> <span class="c"># Show 25 contacts per page</span>

    <span class="n">page</span> <span class="o">=</span> <span class="n">request</span><span class="o">.</span><span class="n">GET</span><span class="o">.</span><span class="n">get</span><span class="p">(</span><span class="s">&#39;page&#39;</span><span class="p">)</span>
    <span class="k">try</span><span class="p">:</span>
        <span class="n">contacts</span> <span class="o">=</span> <span class="n">paginator</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="n">page</span><span class="p">)</span>
    <span class="k">except</span> <span class="n">PageNotAnInteger</span><span class="p">:</span>
        <span class="c"># If page is not an integer, deliver first page.</span>
        <span class="n">contacts</span> <span class="o">=</span> <span class="n">paginator</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="mi">1</span><span class="p">)</span>
    <span class="k">except</span> <span class="n">EmptyPage</span><span class="p">:</span>
        <span class="c"># If page is out of range (e.g. 9999), deliver last page of results.</span>
        <span class="n">contacts</span> <span class="o">=</span> <span class="n">paginator</span><span class="o">.</span><span class="n">page</span><span class="p">(</span><span class="n">paginator</span><span class="o">.</span><span class="n">num_pages</span><span class="p">)</span>

    <span class="k">return</span> <span class="n">render_to_response</span><span class="p">(</span><span class="s">&#39;list.html&#39;</span><span class="p">,</span> <span class="p">{</span><span class="s">&quot;contacts&quot;</span><span class="p">:</span> <span class="n">contacts</span><span class="p">})</span>
</pre></div>
</div>
<p>In the template <tt class="file docutils literal"><span class="pre">list.html</span></tt>, you&#8217;ll want to include navigation between
pages along with any interesting information from the objects themselves:</p>
<div class="highlight-python"><div class="highlight"><pre>{% for contact in contacts %}
    {# Each &quot;contact&quot; is a Contact model object. #}
    {{ contact.full_name|upper }}&lt;br /&gt;
    ...
{% endfor %}

&lt;div class=&quot;pagination&quot;&gt;
    &lt;span class=&quot;step-links&quot;&gt;
        {% if contacts.has_previous %}
            &lt;a href=&quot;?page={{ contacts.previous_page_number }}&quot;&gt;previous&lt;/a&gt;
        {% endif %}

        &lt;span class=&quot;current&quot;&gt;
            Page {{ contacts.number }} of {{ contacts.paginator.num_pages }}.
        &lt;/span&gt;

        {% if contacts.has_next %}
            &lt;a href=&quot;?page={{ contacts.next_page_number }}&quot;&gt;next&lt;/a&gt;
        {% endif %}
    &lt;/span&gt;
&lt;/div&gt;
</pre></div>
</div>
</div>
<div class="section" id="s-paginator-objects">
<span id="paginator-objects"></span><h2><tt class="docutils literal"><span class="pre">Paginator</span></tt> objects<a class="headerlink" href="#paginator-objects" title="Permalink to this headline">¶</a></h2>
<p>The <a class="reference internal" href="#django.core.paginator.Paginator" title="django.core.paginator.Paginator"><tt class="xref py py-class docutils literal"><span class="pre">Paginator</span></tt></a> class has this constructor:</p>
<dl class="class">
<dt id="django.core.paginator.Paginator">
<em class="property">class </em><tt class="descname">Paginator</tt>(<em>object_list</em>, <em>per_page</em>, <em>orphans=0</em>, <em>allow_empty_first_page=True</em>)<a class="reference internal" href="../_modules/django/core/paginator.html#Paginator"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Paginator" title="Permalink to this definition">¶</a></dt>
<dd></dd></dl>

<div class="section" id="s-required-arguments">
<span id="required-arguments"></span><h3>Required arguments<a class="headerlink" href="#required-arguments" title="Permalink to this headline">¶</a></h3>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">object_list</span></tt></dt>
<dd>A list, tuple, Django <tt class="docutils literal"><span class="pre">QuerySet</span></tt>, or other sliceable object with a
<tt class="docutils literal"><span class="pre">count()</span></tt> or <tt class="docutils literal"><span class="pre">__len__()</span></tt> method.</dd>
<dt><tt class="docutils literal"><span class="pre">per_page</span></tt></dt>
<dd>The maximum number of items to include on a page, not including orphans
(see the <tt class="docutils literal"><span class="pre">orphans</span></tt> optional argument below).</dd>
</dl>
</div>
<div class="section" id="s-optional-arguments">
<span id="optional-arguments"></span><h3>Optional arguments<a class="headerlink" href="#optional-arguments" title="Permalink to this headline">¶</a></h3>
<dl class="docutils">
<dt><tt class="docutils literal"><span class="pre">orphans</span></tt></dt>
<dd>The minimum number of items allowed on the last page, defaults to zero.
Use this when you don&#8217;t want to have a last page with very few items.
If the last page would normally have a number of items less than or equal
to <tt class="docutils literal"><span class="pre">orphans</span></tt>, then those items will be added to the previous page (which
becomes the last page) instead of leaving the items on a page by
themselves. For example, with 23 items, <tt class="docutils literal"><span class="pre">per_page=10</span></tt>, and
<tt class="docutils literal"><span class="pre">orphans=3</span></tt>, there will be two pages; the first page with 10 items and
the  second (and last) page with 13 items.</dd>
<dt><tt class="docutils literal"><span class="pre">allow_empty_first_page</span></tt></dt>
<dd>Whether or not the first page is allowed to be empty.  If <tt class="docutils literal"><span class="pre">False</span></tt> and
<tt class="docutils literal"><span class="pre">object_list</span></tt> is  empty, then an <tt class="docutils literal"><span class="pre">EmptyPage</span></tt> error will be raised.</dd>
</dl>
</div>
<div class="section" id="s-methods">
<span id="methods"></span><h3>Methods<a class="headerlink" href="#methods" title="Permalink to this headline">¶</a></h3>
<dl class="method">
<dt id="django.core.paginator.Paginator.page">
<tt class="descclassname">Paginator.</tt><tt class="descname">page</tt>(<em>number</em>)<a class="reference internal" href="../_modules/django/core/paginator.html#Paginator.page"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Paginator.page" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns a <a class="reference internal" href="#django.core.paginator.Page" title="django.core.paginator.Page"><tt class="xref py py-class docutils literal"><span class="pre">Page</span></tt></a> object with the given 1-based index. Raises
<a class="reference internal" href="#django.core.paginator.InvalidPage" title="django.core.paginator.InvalidPage"><tt class="xref py py-exc docutils literal"><span class="pre">InvalidPage</span></tt></a> if the given page number doesn&#8217;t exist.</p>
</dd></dl>

</div>
<div class="section" id="s-attributes">
<span id="attributes"></span><h3>Attributes<a class="headerlink" href="#attributes" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.core.paginator.Paginator.count">
<tt class="descclassname">Paginator.</tt><tt class="descname">count</tt><a class="headerlink" href="#django.core.paginator.Paginator.count" title="Permalink to this definition">¶</a></dt>
<dd><p>The total number of objects, across all pages.</p>
<div class="admonition note">
<p class="first admonition-title">Note</p>
<p class="last">When determining the number of objects contained in <tt class="docutils literal"><span class="pre">object_list</span></tt>,
<tt class="docutils literal"><span class="pre">Paginator</span></tt> will first try calling <tt class="docutils literal"><span class="pre">object_list.count()</span></tt>. If
<tt class="docutils literal"><span class="pre">object_list</span></tt> has no <tt class="docutils literal"><span class="pre">count()</span></tt> method, then <tt class="docutils literal"><span class="pre">Paginator</span></tt> will
fallback to using <tt class="docutils literal"><span class="pre">len(object_list)</span></tt>. This allows objects, such as
Django&#8217;s <tt class="docutils literal"><span class="pre">QuerySet</span></tt>, to use a more efficient <tt class="docutils literal"><span class="pre">count()</span></tt> method when
available.</p>
</div>
</dd></dl>

<dl class="attribute">
<dt id="django.core.paginator.Paginator.num_pages">
<tt class="descclassname">Paginator.</tt><tt class="descname">num_pages</tt><a class="headerlink" href="#django.core.paginator.Paginator.num_pages" title="Permalink to this definition">¶</a></dt>
<dd><p>The total number of pages.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.core.paginator.Paginator.page_range">
<tt class="descclassname">Paginator.</tt><tt class="descname">page_range</tt><a class="headerlink" href="#django.core.paginator.Paginator.page_range" title="Permalink to this definition">¶</a></dt>
<dd><p>A 1-based range of page numbers, e.g., <tt class="docutils literal"><span class="pre">[1,</span> <span class="pre">2,</span> <span class="pre">3,</span> <span class="pre">4]</span></tt>.</p>
</dd></dl>

</div>
</div>
<div class="section" id="s-invalidpage-exceptions">
<span id="invalidpage-exceptions"></span><h2><tt class="docutils literal"><span class="pre">InvalidPage</span></tt> exceptions<a class="headerlink" href="#invalidpage-exceptions" title="Permalink to this headline">¶</a></h2>
<dl class="exception">
<dt id="django.core.paginator.InvalidPage">
<em class="property">exception </em><tt class="descname">InvalidPage</tt><a class="reference internal" href="../_modules/django/core/paginator.html#InvalidPage"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.InvalidPage" title="Permalink to this definition">¶</a></dt>
<dd><p>A base class for exceptions raised when a paginator is passed an invalid
page number.</p>
</dd></dl>

<p>The <a class="reference internal" href="#django.core.paginator.Paginator.page" title="django.core.paginator.Paginator.page"><tt class="xref py py-meth docutils literal"><span class="pre">Paginator.page()</span></tt></a> method raises an exception if the requested page is
invalid (i.e., not an integer) or contains no objects. Generally, it&#8217;s enough
to trap the <tt class="docutils literal"><span class="pre">InvalidPage</span></tt> exception, but if you&#8217;d like more granularity, you
can trap either of the following exceptions:</p>
<dl class="exception">
<dt id="django.core.paginator.PageNotAnInteger">
<em class="property">exception </em><tt class="descname">PageNotAnInteger</tt><a class="reference internal" href="../_modules/django/core/paginator.html#PageNotAnInteger"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.PageNotAnInteger" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised when <tt class="docutils literal"><span class="pre">page()</span></tt> is given a value that isn&#8217;t an integer.</p>
</dd></dl>

<dl class="exception">
<dt id="django.core.paginator.EmptyPage">
<em class="property">exception </em><tt class="descname">EmptyPage</tt><a class="reference internal" href="../_modules/django/core/paginator.html#EmptyPage"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.EmptyPage" title="Permalink to this definition">¶</a></dt>
<dd><p>Raised when <tt class="docutils literal"><span class="pre">page()</span></tt> is given a valid value but no objects exist on that
page.</p>
</dd></dl>

<p>Both of the exceptions are subclasses of <a class="reference internal" href="#django.core.paginator.InvalidPage" title="django.core.paginator.InvalidPage"><tt class="xref py py-exc docutils literal"><span class="pre">InvalidPage</span></tt></a>, so you can handle
them both with a simple <tt class="docutils literal"><span class="pre">except</span> <span class="pre">InvalidPage</span></tt>.</p>
</div>
<div class="section" id="s-page-objects">
<span id="page-objects"></span><h2><tt class="docutils literal"><span class="pre">Page</span></tt> objects<a class="headerlink" href="#page-objects" title="Permalink to this headline">¶</a></h2>
<p>You usually won&#8217;t construct <tt class="docutils literal"><span class="pre">Page</span></tt> objects by hand &#8211; you&#8217;ll get them
using <a class="reference internal" href="#django.core.paginator.Paginator.page" title="django.core.paginator.Paginator.page"><tt class="xref py py-meth docutils literal"><span class="pre">Paginator.page()</span></tt></a>.</p>
<dl class="class">
<dt id="django.core.paginator.Page">
<em class="property">class </em><tt class="descname">Page</tt>(<em>object_list</em>, <em>number</em>, <em>paginator</em>)<a class="reference internal" href="../_modules/django/core/paginator.html#Page"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Page" title="Permalink to this definition">¶</a></dt>
<dd><p>A page acts like a sequence of <a class="reference internal" href="#django.core.paginator.Page.object_list" title="django.core.paginator.Page.object_list"><tt class="xref py py-attr docutils literal"><span class="pre">Page.object_list</span></tt></a> when using
<tt class="docutils literal"><span class="pre">len()</span></tt> or iterating it directly.</p>
</dd></dl>

<div class="section" id="s-id1">
<span id="id1"></span><h3>Methods<a class="headerlink" href="#id1" title="Permalink to this headline">¶</a></h3>
<dl class="method">
<dt id="django.core.paginator.Page.has_next">
<tt class="descclassname">Page.</tt><tt class="descname">has_next</tt>()<a class="reference internal" href="../_modules/django/core/paginator.html#Page.has_next"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Page.has_next" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <tt class="docutils literal"><span class="pre">True</span></tt> if there&#8217;s a next page.</p>
</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.has_previous">
<tt class="descclassname">Page.</tt><tt class="descname">has_previous</tt>()<a class="reference internal" href="../_modules/django/core/paginator.html#Page.has_previous"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Page.has_previous" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <tt class="docutils literal"><span class="pre">True</span></tt> if there&#8217;s a previous page.</p>
</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.has_other_pages">
<tt class="descclassname">Page.</tt><tt class="descname">has_other_pages</tt>()<a class="reference internal" href="../_modules/django/core/paginator.html#Page.has_other_pages"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Page.has_other_pages" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns <tt class="docutils literal"><span class="pre">True</span></tt> if there&#8217;s a next <em>or</em> previous page.</p>
</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.next_page_number">
<tt class="descclassname">Page.</tt><tt class="descname">next_page_number</tt>()<a class="reference internal" href="../_modules/django/core/paginator.html#Page.next_page_number"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Page.next_page_number" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the next page number. Raises <a class="reference internal" href="#django.core.paginator.InvalidPage" title="django.core.paginator.InvalidPage"><tt class="xref py py-exc docutils literal"><span class="pre">InvalidPage</span></tt></a> if next page
doesn&#8217;t exist.</p>
</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.previous_page_number">
<tt class="descclassname">Page.</tt><tt class="descname">previous_page_number</tt>()<a class="reference internal" href="../_modules/django/core/paginator.html#Page.previous_page_number"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Page.previous_page_number" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the previous page number. Raises <a class="reference internal" href="#django.core.paginator.InvalidPage" title="django.core.paginator.InvalidPage"><tt class="xref py py-exc docutils literal"><span class="pre">InvalidPage</span></tt></a> if previous
page doesn&#8217;t exist.</p>
</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.start_index">
<tt class="descclassname">Page.</tt><tt class="descname">start_index</tt>()<a class="reference internal" href="../_modules/django/core/paginator.html#Page.start_index"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Page.start_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the 1-based index of the first object on the page, relative to all
of the objects in the paginator&#8217;s list. For example, when paginating a list
of 5 objects with 2 objects per page, the second page&#8217;s
<a class="reference internal" href="#django.core.paginator.Page.start_index" title="django.core.paginator.Page.start_index"><tt class="xref py py-meth docutils literal"><span class="pre">start_index()</span></tt></a> would return <tt class="docutils literal"><span class="pre">3</span></tt>.</p>
</dd></dl>

<dl class="method">
<dt id="django.core.paginator.Page.end_index">
<tt class="descclassname">Page.</tt><tt class="descname">end_index</tt>()<a class="reference internal" href="../_modules/django/core/paginator.html#Page.end_index"><span class="viewcode-link">[source]</span></a><a class="headerlink" href="#django.core.paginator.Page.end_index" title="Permalink to this definition">¶</a></dt>
<dd><p>Returns the 1-based index of the last object on the page, relative to all
of the objects in the paginator&#8217;s list. For example, when paginating a list
of 5 objects with 2 objects per page, the second page&#8217;s
<a class="reference internal" href="#django.core.paginator.Page.end_index" title="django.core.paginator.Page.end_index"><tt class="xref py py-meth docutils literal"><span class="pre">end_index()</span></tt></a> would return <tt class="docutils literal"><span class="pre">4</span></tt>.</p>
</dd></dl>

</div>
<div class="section" id="s-id2">
<span id="id2"></span><h3>Attributes<a class="headerlink" href="#id2" title="Permalink to this headline">¶</a></h3>
<dl class="attribute">
<dt id="django.core.paginator.Page.object_list">
<tt class="descclassname">Page.</tt><tt class="descname">object_list</tt><a class="headerlink" href="#django.core.paginator.Page.object_list" title="Permalink to this definition">¶</a></dt>
<dd><p>The list of objects on this page.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.core.paginator.Page.number">
<tt class="descclassname">Page.</tt><tt class="descname">number</tt><a class="headerlink" href="#django.core.paginator.Page.number" title="Permalink to this definition">¶</a></dt>
<dd><p>The 1-based page number for this page.</p>
</dd></dl>

<dl class="attribute">
<dt id="django.core.paginator.Page.paginator">
<tt class="descclassname">Page.</tt><tt class="descname">paginator</tt><a class="headerlink" href="#django.core.paginator.Page.paginator" title="Permalink to this definition">¶</a></dt>
<dd><p>The associated <a class="reference internal" href="#django.core.paginator.Paginator" title="django.core.paginator.Paginator"><tt class="xref py py-class docutils literal"><span class="pre">Paginator</span></tt></a> object.</p>
</dd></dl>

</div>
</div>
</div>


          </div>
        </div>
      </div>
      
        
          <div class="yui-b" id="sidebar">
            
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
  <h3><a href="../contents.html">Table Of Contents</a></h3>
  <ul>
<li><a class="reference internal" href="#">Pagination</a><ul>
<li><a class="reference internal" href="#example">Example</a></li>
<li><a class="reference internal" href="#using-paginator-in-a-view">Using <tt class="docutils literal"><span class="pre">Paginator</span></tt> in a view</a></li>
<li><a class="reference internal" href="#paginator-objects"><tt class="docutils literal"><span class="pre">Paginator</span></tt> objects</a><ul>
<li><a class="reference internal" href="#required-arguments">Required arguments</a></li>
<li><a class="reference internal" href="#optional-arguments">Optional arguments</a></li>
<li><a class="reference internal" href="#methods">Methods</a></li>
<li><a class="reference internal" href="#attributes">Attributes</a></li>
</ul>
</li>
<li><a class="reference internal" href="#invalidpage-exceptions"><tt class="docutils literal"><span class="pre">InvalidPage</span></tt> exceptions</a></li>
<li><a class="reference internal" href="#page-objects"><tt class="docutils literal"><span class="pre">Page</span></tt> objects</a><ul>
<li><a class="reference internal" href="#id1">Methods</a></li>
<li><a class="reference internal" href="#id2">Attributes</a></li>
</ul>
</li>
</ul>
</li>
</ul>

  <h3>Browse</h3>
  <ul>
    
      <li>Prev: <a href="logging.html">Logging</a></li>
    
    
      <li>Next: <a href="python3.html">Porting to Python 3</a></li>
    
  </ul>
  <h3>You are here:</h3>
  <ul>
      <li>
        <a href="../index.html">Django 1.7.8.dev20150401230226 documentation</a>
        
          <ul><li><a href="index.html">Using Django</a>
        
        <ul><li>Pagination</li></ul>
        </li></ul>
      </li>
  </ul>

  <h3>This Page</h3>
  <ul class="this-page-menu">
    <li><a href="../_sources/topics/pagination.txt"
           rel="nofollow">Show Source</a></li>
  </ul>
<div id="searchbox" style="display: none">
  <h3>Quick search</h3>
    <form class="search" action="../search.html" method="get">
      <input type="text" name="q" />
      <input type="submit" value="Go" />
      <input type="hidden" name="check_keywords" value="yes" />
      <input type="hidden" name="area" value="default" />
    </form>
    <p class="searchtip" style="font-size: 90%">
    Enter search terms or a module, class or function name.
    </p>
</div>
<script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
              <h3>Last update:</h3>
              <p class="topless">Apr 02, 2015</p>
          </div>
        
      
    </div>

    <div id="ft">
      <div class="nav">
    &laquo; <a href="logging.html" title="Logging">previous</a>
     |
    <a href="index.html" title="Using Django" accesskey="U">up</a>
   |
    <a href="python3.html" title="Porting to Python 3">next</a> &raquo;</div>
    </div>
  </div>

      <div class="clearer"></div>
    </div>
  </body>
</html>